/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.sequence.preference;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.ConsiderIgnoreFragment;
import org.eclipse.uml2.uml.Continuation;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Gate;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.uml2.uml.InteractionConstraint;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.InteractionUse;
import org.eclipse.uml2.uml.Lifeline;
import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
import org.eclipse.uml2.uml.OccurrenceSpecification;
import org.eclipse.uml2.uml.StateInvariant;
import org.eclipse.uml2.uml.util.UMLSwitch;

import com.cea.papyrus.diagram.classdiagram.preference.ClassDiagramPreferenceConstants;
import com.cea.papyrus.diagram.sequence.Activator;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * this class sets default preference values for graphical elements.
 * 
 * @author ymortier <yann.mortier@obeo.fr>
 */
public abstract class PreferenceSetter {

    /** Saved data. */
    private static Map<EClass, PreferenceSetter> lazyPreferenceSetterMap =
            new HashMap<EClass, PreferenceSetter>();

    /**
     * Sets the preference for the element.
     * 
     * @param graphElement
     *            the graph element.
     */
    public abstract void setPreference(GraphElement graphElement);

    /**
     * Returns the appropiate <code>PreferenceSetter</code>.
     * 
     * @return the appropiate <code>PreferenceSetter</code>.
     */
    public static PreferenceSetter getPreferenceSetter(EObject umlType) {
        PreferenceSetter preferenceSetter = lazyPreferenceSetterMap.get(umlType.eClass());
        if (preferenceSetter == null) {
            PreferenceSetterProvider preferenceSetterProvider = new PreferenceSetterProvider();
            preferenceSetter = preferenceSetterProvider.doSwitch(umlType);
            lazyPreferenceSetterMap.put(umlType.eClass(), preferenceSetter);
        }
        return preferenceSetter;
    }

    /**
     * Tge default preference setter.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class DefaultPreferenceSetter extends PreferenceSetter {

        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(new RGB(255, 255, 255));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(new RGB(0, 0, 0));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(new RGB(0, 0, 0));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(new RGB(0, 0, 0));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceLifelineFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily("Arial");
                graphElement.setFontSize(10);
            }
        }

    }

    /**
     * Preference setter for interactions.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class InteractionPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceInteractionFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for interactionfragments.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class InteractionFragmentPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFragmentBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFragmentBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFragmentFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionFragmentFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceInteractionFragmentFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for lifelines.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class LifelinePreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceLifelineBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceLifelineBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceLifelineFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceLifelineFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceLifelineFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for interactionuses.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class InteractionUsePreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionUseBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionUseBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionUseFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionUseFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceInteractionUseFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for gates.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class GatePreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceGateBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceGateBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceGateFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceGateFontColor(store));
            }
            FontData[] fontData = SequenceDiagramPreferenceConstants.getPreferenceGateFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for occurrencespecifications.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class OccurrenceSpecificationPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceOccurrenceSpecificationBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceOccurrenceSpecificationBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceOccurrenceSpecificationFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceOccurrenceSpecificationFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceOccurrenceSpecificationFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for interactionconstraints.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class InteractionConstraintPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionConstraintBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionConstraintBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionConstraintFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceInteractionConstraintFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceInteractionConstraintFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for executionspecifications.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class ExecutionSpecificationPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionSpecificationBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionSpecificationBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionSpecificationFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionSpecificationFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceExecutionSpecificationFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for stateinvariants.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class StateInvariantPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceStateInvariantBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceStateInvariantBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceStateInvariantFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceStateInvariantFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceStateInvariantFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for messageoccurrencespecifications.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class MessageOccurrenceSpecificationPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceMessageOccurrenceSpecificationBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceMessageOccurrenceSpecificationBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceMessageOccurrenceSpecificationFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceMessageOccurrenceSpecificationFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceMessageOccurrenceSpecificationFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for executionoccurrencespecifications.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class ExecutionOccurrenceSpecificationPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionOccurrenceSpecificationBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionOccurrenceSpecificationBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionOccurrenceSpecificationFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceExecutionOccurrenceSpecificationFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceExecutionOccurrenceSpecificationFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for combinedfragments.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class CombinedFragmentPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceCombinedFragmentBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceCombinedFragmentBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceCombinedFragmentFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceCombinedFragmentFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceCombinedFragmentFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for continuations.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class ContinuationPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceContinuationBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceContinuationBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceContinuationFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceContinuationFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants.getPreferenceContinuationFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for comments.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class CommentPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(ClassDiagramPreferenceConstants
                        .getPreferenceCommentBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(ClassDiagramPreferenceConstants
                        .getPreferenceCommentBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(ClassDiagramPreferenceConstants
                        .getPreferenceCommentFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(ClassDiagramPreferenceConstants
                        .getPreferenceCommentFontColor(store));
            }
            FontData[] fontData =
                    ClassDiagramPreferenceConstants.getPreferenceCommentFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Preference setter for considerignorefragments.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class ConsiderIgnoreFragmentPreferenceSetter extends PreferenceSetter {
        /**
         * @see com.cea.papyrus.diagram.sequence.preference.PreferenceSetter#setPreference(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
         */
        @Override
        public void setPreference(GraphElement graphElement) {
            IPreferenceStore store = Activator.getDefault().getPreferenceStore();
            if (graphElement.getBackgroundColor() == null) {
                graphElement.setBackgroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceConsiderIgnoreFragmentBackgroundColor(store));
            }
            if (graphElement.getBorderColor() == null) {
                graphElement.setBorderColor(SequenceDiagramPreferenceConstants
                        .getPreferenceConsiderIgnoreFragmentBorderColor(store));
            }
            if (graphElement.getFontColor() == null) {
                graphElement.setFontColor(SequenceDiagramPreferenceConstants
                        .getPreferenceConsiderIgnoreFragmentFontColor(store));
            }
            if (graphElement.getForegroundColor() == null) {
                graphElement.setForegroundColor(SequenceDiagramPreferenceConstants
                        .getPreferenceConsiderIgnoreFragmentFontColor(store));
            }
            FontData[] fontData =
                    SequenceDiagramPreferenceConstants
                            .getPreferenceConsiderIgnoreFragmentFont(store);
            if ((graphElement.getFontFamily() == null || graphElement.getFontFamily().equals(""))
                    && fontData.length > 0) {
                graphElement.setFontFamily(fontData[0].getName());
                graphElement.setFontSize(fontData[0].getHeight());
            }
        }
    }

    /**
     * Provider for preference setter.
     * 
     * @author ymortier <yann.mortier@obeo.fr>
     */
    private static class PreferenceSetterProvider extends UMLSwitch<PreferenceSetter> {

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseInteraction(org.eclipse.uml2.uml.Interaction)
         */
        @Override
        public PreferenceSetter caseInteraction(Interaction interaction) {
            return new InteractionPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseInteractionFragment(org.eclipse.uml2.uml.InteractionFragment)
         */
        @Override
        public PreferenceSetter caseInteractionFragment(InteractionFragment interactionFragment) {
            return new InteractionFragmentPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseLifeline(org.eclipse.uml2.uml.Lifeline)
         */
        @Override
        public PreferenceSetter caseLifeline(Lifeline lifeline) {
            return new LifelinePreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseInteractionUse(org.eclipse.uml2.uml.InteractionUse)
         */
        @Override
        public PreferenceSetter caseInteractionUse(InteractionUse interactionUse) {
            return new InteractionUsePreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseGate(org.eclipse.uml2.uml.Gate)
         */
        @Override
        public PreferenceSetter caseGate(Gate gate) {
            return new GatePreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseOccurrenceSpecification(org.eclipse.uml2.uml.OccurrenceSpecification)
         */
        @Override
        public PreferenceSetter caseOccurrenceSpecification(
                OccurrenceSpecification occurrenceSpecification) {
            return new OccurrenceSpecificationPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseInteractionConstraint(org.eclipse.uml2.uml.InteractionConstraint)
         */
        @Override
        public PreferenceSetter caseInteractionConstraint(
                InteractionConstraint interactionConstraint) {
            return new InteractionConstraintPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseExecutionSpecification(org.eclipse.uml2.uml.ExecutionSpecification)
         */
        @Override
        public PreferenceSetter caseExecutionSpecification(
                ExecutionSpecification executionSpecification) {
            return new ExecutionSpecificationPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseStateInvariant(org.eclipse.uml2.uml.StateInvariant)
         */
        @Override
        public PreferenceSetter caseStateInvariant(StateInvariant stateInvariant) {
            return new StateInvariantPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseMessageOccurrenceSpecification(org.eclipse.uml2.uml.MessageOccurrenceSpecification)
         */
        @Override
        public PreferenceSetter caseMessageOccurrenceSpecification(
                MessageOccurrenceSpecification messageOccurrenceSpecification) {
            return new MessageOccurrenceSpecificationPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseExecutionOccurrenceSpecification(org.eclipse.uml2.uml.ExecutionOccurrenceSpecification)
         */
        @Override
        public PreferenceSetter caseExecutionOccurrenceSpecification(
                ExecutionOccurrenceSpecification executionOccurrenceSpecification) {
            return new ExecutionOccurrenceSpecificationPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseCombinedFragment(org.eclipse.uml2.uml.CombinedFragment)
         */
        @Override
        public PreferenceSetter caseCombinedFragment(CombinedFragment combinedFragment) {
            return new CombinedFragmentPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseContinuation(org.eclipse.uml2.uml.Continuation)
         */
        @Override
        public PreferenceSetter caseContinuation(Continuation continuation) {
            return new ContinuationPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseConsiderIgnoreFragment(org.eclipse.uml2.uml.ConsiderIgnoreFragment)
         */
        @Override
        public PreferenceSetter caseConsiderIgnoreFragment(
                ConsiderIgnoreFragment considerIgnoreFragment) {
            return new ConsiderIgnoreFragmentPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseElement(org.eclipse.uml2.uml.Element)
         */
        @Override
        public PreferenceSetter caseElement(Element object) {
            return new DefaultPreferenceSetter();
        }

        /**
         * @see org.eclipse.uml2.uml.util.UMLSwitch#caseComment(org.eclipse.uml2.uml.Comment)
         */
        @Override
        public PreferenceSetter caseComment(Comment object) {
            return new CommentPreferenceSetter();
        }
    }

}
